/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package src;

import java.util.HashMap;
import java.util.Set;
import java.io.*;
import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class Visualizar extends HttpServlet{
    
    public void doGet(HttpServletRequest request, HttpServletResponse response){
        processar(request,response);
    }
    public void doPost(HttpServletRequest request, HttpServletResponse response){
        processar(request,response);
    }

    private void processar(HttpServletRequest request, HttpServletResponse response) {
       
        try{
			PrintWriter saida = response.getWriter();
			listaUsuarios listaObj = new listaUsuarios();
			HashMap<String, Usuario> listaUser = new HashMap<>();
			Usuario user = new Usuario();
			
			HttpSession session = request.getSession();
            if(session.getAttribute("listaObj") == null){
				saida.println("null");
                try {
					FileInputStream fis = new FileInputStream("usuarios.obj");
					ObjectInputStream ois = new ObjectInputStream(fis);
					listaObj = (listaUsuarios) ois.readObject();
					session.setAttribute("listaObj", listaObj);
				} catch (Exception e) {
				}
			}else{
				listaObj = (listaUsuarios) session.getAttribute("listaObj");
			}
			
			String url = "busca.jsp";
			
            RequestDispatcher dispatcher = request.getRequestDispatcher(url);
            dispatcher.forward(request, response);
            
        }catch(Exception e){
            e.printStackTrace();
		}
    }
}